package com.su.service.impl;


import com.su.service.IMailService;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.mail.javamail.MimeMessageHelper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.mail.MessagingException;
import javax.mail.internet.MimeMessage;


@Service
public class MailServiceImpl implements IMailService {

    @Resource
    private JavaMailSender  mailSender;

    @Override
    public void sendActivationMail(String mailTo, String activationCode) {
        SimpleMailMessage simpleMailMessage = new SimpleMailMessage();
        simpleMailMessage.setSubject("爱旅行注册激活码");
        simpleMailMessage.setTo(mailTo);
        simpleMailMessage.setText("您的激活码是:"+ activationCode);
        mailSender.send(simpleMailMessage);
    }

    @Override
    public void sendHtmlMail(String mailTo, String content) throws MessagingException {
        MimeMessage message = mailSender.createMimeMessage();
        MimeMessageHelper helper=new MimeMessageHelper(message,true);
        helper.setSubject("爱旅行注册激活码");
        helper.setTo(mailTo);
        helper.setText(content,true);
        mailSender.send(message);
//        MimeMessageHelper helper = new MimeMessageHelper(, true);
    }
}
